package org.fjsei.yewu.config;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import java.io.IOException;

@SpringBootApplication
@ComponentScan(basePackages = "org.fjsei.yewu")
public class SqlGeneratorApplication implements CommandLineRunner {

    private final SqlGenerator sqlGenerator;

    public SqlGeneratorApplication(SqlGenerator sqlGenerator) {
        this.sqlGenerator = sqlGenerator;
    }

    public static void main(String[] args) {
        SpringApplication.run(SqlGeneratorApplication.class, args);
    }

    @Override
    public void run(String... args) throws IOException {
        String outputDir = "./sql-scripts";
        
        System.out.println("开始生成SQL脚本...");
        System.out.println("输出目录: " + outputDir);
        
        sqlGenerator.generateSqlScripts(outputDir);
        
        System.out.println("SQL脚本生成完成！");
        System.out.println("请检查以下文件:");
        System.out.println("- " + outputDir + "/01-create-tables.sql");
        System.out.println("- " + outputDir + "/99-drop-tables.sql");
        System.out.println("- " + outputDir + "/00-README.md");
    }
}